<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据分析面板</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
    <link rel="stylesheet" href="../../styles/common.css" />
    <link rel="stylesheet" href="../../styles/page.css" />
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background-color: #f5f6fa;
            padding: 20px;
        }

        .breadcrumb {
            margin-bottom: 20px;
            color: #666;
        }

        .stats-container {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }

        .stat-card h3 {
            color: #666;
            font-size: 14px;
            margin-bottom: 10px;
        }

        .stat-card .number {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }

        .tables-container {
           display: flex;
            gap: 20px;
        }

        .table-card {
            min-width: 450px;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }

        .table-card h2 {
            margin-bottom: 20px;
            font-size: 16px;
            color: #333;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            color: #666;
            font-weight: normal;
        }

        td {
            color: #333;
        }
    </style>
</head>
<body>
    <div class="container" id="statisticContainer" v-loading="loading">
        <h1 style="margin-bottom: 20px;font-size: 20px">舆情分析</h1>
        <div class="stats-container">
            <div class="stat-card">
                <h3>本月新增员工数</h3>
                <div class="number">{{statisticData.monthlyNewEmployees}}</div>
            </div>
            <div class="stat-card">
                <h3>本月新增菜品数</h3>
                <div class="number">{{statisticData.monthlyNewDishes}}</div>
            </div>
            <div class="stat-card">
                <h3>今日下单量</h3>
                <div class="number">{{statisticData.todayOrders}}</div>
            </div>
            <div class="stat-card">
                <h3>总收入</h3>
                <div class="number">{{statisticData.totalRevenue}}</div>
            </div>
        </div>
        <div class="tables-container">
            <div class="table-card">
                <h2>热销榜单</h2>
                <table>
                    <thead>
                    <tr>
                        <th>排名</th>
                        <th>菜品名</th>
                        <th>下单量</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(dish, index) in hotDishes" :key="dish.dishId">
                        <td>{{index + 1}}</td>
                        <td>{{dish.name}}</td>
                        <td>{{dish.number}}</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="table-card">
                <h2>24小时下单趋势分析</h2>
                <table>
                    <thead>
                    <tr>
                        <th>排名</th>
                        <th>小时</th>
                        <th>下单量</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(order, index) in hourlyOrders" :key="index" v-if="index >= 11 && index <= 18">
                        <td>{{index - 10}}</td>
                        <td>{{order.hour}}</td>
                        <td>{{order.count}}</td>
                    </tr>
                    </tbody>
                </table>
            </div>
            </div>
        </div>
    </div>


<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
    <script src="../../js/request.js"></script>

    <script src="../../api/statistic.js"></script>

<script>
    new Vue({
        el: '#statisticContainer',
        data() {
            return {
                loading: false,
                statisticData: {
                    monthlyNewDishes: 0,
                    monthlyNewEmployees: 0,
                    todayOrders: 0,
                    totalRevenue: 0
                },  
                hotDishes:[]
               
            }
        },
        computed: {},
        watch:{

        },
        created() {

        },
        mounted() {
    this.getStatisticData();
    this.getHotDishes();
    this.getHourlyOrders();
        },
        methods: {
           async getStatisticData(){
            this.loading = true;
             const  res = await  getStatistic()
               this.statisticData = res.data
               this.loading = false
            },
            async getHotDishes() {
            
                    const res = await getHotDishes()
                    this.loading = true;
                    this.hotDishes = res.data
                    this.loading = false
                    console.log(this.hotDishes)
               
            },
            async getHourlyOrders() {
                this.loading = true;

                const res = await getHourlyOrders()
                this.hourlyOrders = res.data
                this.loading = false

                console.log(this.hourlyOrders)

            }
        }
    })
</script>
</body>
</html>